package cn.bby.query.server.infrastructure.config;

import cn.bby.jtk.base.config.CommonThreadPoolConfig;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;

/**
 * @author wangbenyin
 * @version 1.0
 * @date 2025/06/05
 * @since 17
 */
@Configuration
@ConfigurationProperties("query.thread-pool")
public class BeanConfig {

    @Autowired
    private RedisProperties redisProperties;

    private CommonThreadPoolConfig consumerThreadPool = new CommonThreadPoolConfig();

    @Bean
    public ExecutorService consumerThreadPool() {
        return consumerThreadPool.executorService();
    }

    private CommonThreadPoolConfig dataLoadThreadPool = new CommonThreadPoolConfig();

    @Bean
    public ExecutorService dataLoadThreadPool() {
        return dataLoadThreadPool.executorService();
    }

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://" + redisProperties.getHost() + ":" + redisProperties.getPort())
                .setPassword(redisProperties.getPassword());
        return Redisson.create(config);
    }
}
